# 
# To change this template, choose Tools | Templates
# and open the template in the editor.
 

require "active_record"
require File.join(File.dirname(__FILE__),'..','..','commonlib','book')
require File.join(File.dirname(__FILE__),'..','..','commonlib','author')
require File.join(File.dirname(__FILE__),'..','..','commonlib','tag')
require File.join(File.dirname(__FILE__),'..','..','commonlib','user')
require File.join(File.dirname(__FILE__),'..','..','commonlib','bookedition')
require File.join(File.dirname(__FILE__),'..','..','commonlib','bookreview')
require File.join(File.dirname(__FILE__),'..','..','commonlib','reading')

ActiveRecord::Base.logger = Logger.new(STDERR)
ActiveRecord::Base.colorize_logging = false

if ARGV.size == 2 
  if ARGV[0] == '-db'
    db = ARGV[1]
  end
end

ActiveRecord::Base.establish_connection(
  :adapter => "mysql",
  :host  => "localhost",
  :database => db
)

ActiveRecord::Schema.define do
  create_table(:books,:force => 'true') do |table|
    table.column :LTWorkID, :integer
    table.column :title, :string
    table.column :author_id, :integer
    table.column :ISBN, :string
  end

  create_table(:authors,:force => 'true') do |table|
    table.column :nameFirst, :string
    table.column :nameLast, :string
    table.column :nameMiddle, :string
  end
    
  create_table(:tags,:force => 'true') do |table|
    table.column :tag, :string
    table.column :book_id, :integer
    table.column :user_id, :integer
  end
    
  create_table(:users,:force => 'true') do |table|
    table.column :nameFirst, :string
    table.column :nameLast, :string
    table.column :userSince, :date, :default => Date.today()
    table.column :loginID, :string
    table.column :password, :string
  end

  create_table(:bookEditions,:force => 'true') do |table|
    table.column :user_id, :integer
    table.column :book_id, :integer
    table.column :rating, :string
  end

    create_table(:bookReviews,:force => 'true') do |table|
    table.column :user_id, :integer
    table.column :book_id, :integer
    table.column :review, :text
  end

end


